package principal;

public class Vetor {
	
	private double x;
	private double y;
	private double z;
	
	public Vetor(double x, double y, double z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	public Vetor soma(Vetor p){
		Vetor ret = new Vetor(this.x + p.getX(), this.y + p.getY(), this.z + p.getZ());
		return ret;
	}
	
	public Vetor sub(Vetor p){
		Vetor ret = new Vetor(this.x - p.getX(), this.y - p.getY(), this.z - p.getZ());
		return ret;
	}
	
	public Vetor produtoVetorial(Vetor v){
		double i = (this.y * v.getZ()) - (this.z * v.getY());
		double j = (this.z * v.getX()) - (this.x * v.getZ());
		double k = (this.x * v.getY()) - (this.y * v.getX());

		return new Vetor(i,j,k);
	}
	
	public double produtoEscalar(Vetor v){
		return (this.x * v.getX()) + (this.y * v.getY()) + (this.z * v.getZ());
	}
	
	public double getModulo(){
		double t = this.produtoEscalar(this);
		return Math.sqrt(t);
	}
	
	public Vetor normalizar(){
		
		double modulo = this.getModulo();
		this.x = this.x / modulo;
		this.y = this.y / modulo;
		this.z = this.z / modulo;
		
		return this;
	}
	
	public void dividirEscalar(double escalar){
		this.x = this.x / escalar;
		this.y = this.y / escalar;
		this.z = this.z / escalar;
		
	}
	
	public Vetor multiplicarEscalar(double escalar){
		double x1 = this.x * escalar;
		double y1 = this.y * escalar;
		double z1 = this.z * escalar;
		
		return new Vetor(x1,y1,z1);
	}
	
	public Ponto toPonto() {
		return new Ponto(x,y,z);
	}
	
	public void refletir() {
		this.x *= -1;
		this.y *= -1;
		this.z *= -1;
	}
	
	public void set(double x, double y, double z)
	{
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	public void set(Vetor v)
	{
		this.x = v.x;
		this.y = v.y;
		this.z = v.z;
	}
	
	public double getX() {
		return x;
	}

	public void setX(double x) {
		this.x = x;
	}

	public double getY() {
		return y;
	}

	public void setY(double y) {
		this.y = y;
	}

	public double getZ() {
		return z;
	}

	public void setZ(double z) {
		this.z = z;
	}
	
}
